import React from 'react';
import { connect } from 'dva'
import { Form, Select, Input, Button, Card, Row, Col, DatePicker } from 'antd';
import PageHeaderLayout from 'components/Layout/PageHeaderLayout';
import FooterToolbar from 'components/FooterToolbar';
import DoAddReceiptForm from './DoAddReceiptForm';

const FormItem = Form.Item;
const Option = Select.Option;

const receiptAdds = ({ location, dispatch, receiptAdd, loading }) => {
  const { pagination, items, isShowSelect, currentRecord, onSelectedReceipter, rowClicked ,paymentPattern,paymentNumStatus} = receiptAdd;
  const currentReceipter = receiptAdd.currentReceipter != undefined && receiptAdd.currentReceipter != null ? receiptAdd.currentReceipter : "未找到";
  const receiptAccounts = currentReceipter.allFinancialAccount;
  const listProps = {
    dataSource: items,
    loading: loading.effects['receiptAdd/query'],
    pagination,
    pageChangeAction: 'receiptAdd/query',
    dispatch,
    location,
    currentRecord,

    visible: isShowSelect,
    showOrClosePop(event) {
      dispatch({
        type: 'receiptAdd/isShowSelect',
        payload: {
          visible: event
        }
      })
    },
    onSelectRows(selectedRowKeys, selectRows) {
      if (selectRows != null && selectRows.length > 0) {
        dispatch({
          type: 'receiptAdd/updateCurrentRecord',
          payload: {
            record: selectRows[0],
          }
        })
        dispatch({
          type: 'receiptAdd/isShowSelect',
          payload: {
            visible: false
          }
        })
      }
    },

  }

  const addProps = {
    loading,
    paymentPattern,
    receiptAccounts,
    currentReceipter,
    dispatch: dispatch,
    listProps,
    onSelectedReceipter,
    paymentNumStatus,
    doAdd(values) {
      dispatch({
        type: 'receiptAdd/create',
        payload: {
          ...values,
          businessType: "PERCENTAGE",
          receiptType: "RECEIPT",
          manualEntry: true
        }
      })
    }
  };

  return (
    <Card>
      <DoAddReceiptForm {...addProps} />
    </Card>


  )
};

export default connect(({ receiptAdd, loading }) => ({ receiptAdd, loading }))(receiptAdds)
